/*
*****************************************************************
* Copyright All Reserved © 2015-2025 Solonix-Chu
*****************************************************************
*/

#ifndef __UORB_DEVICE_H__
#define __UORB_DEVICE_H__

#include "uORB.h"
#include <rtthread.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/* control command code */
#define UORB_DEVICE_CTRL_CHECK        (0x01) /* args: int* updated */
#define UORB_DEVICE_CTRL_SET_INTERVAL (0x02) /* args: unsigned* interval_ms */
#define UORB_DEVICE_CTRL_GET_STATUS   (0x03) /* args: struct uorb_device_status* */
#define UORB_DEVICE_CTRL_EXISTS       (0x04) /* args: int* exists */

struct uorb_device_status
{
    const char                  *name;
    const struct orb_metadata_s *meta;
    rt_uint8_t                   instance;
    rt_uint8_t                   queue_size;
    rt_uint32_t                  generation;
    rt_uint8_t                   subscriber_count;
    rt_bool_t                    advertised;
    rt_bool_t                    data_valid;
};

/* Register/unregister device interface */
int rt_uorb_register_topic(const struct orb_metadata_s *meta, rt_uint8_t instance);
int rt_uorb_unregister_topic(const struct orb_metadata_s *meta, rt_uint8_t instance);

/* Generate device node name: ensure it does not exceed RT_NAME_MAX, the format is prefix truncated + instance number */
void uorb_make_dev_name(const struct orb_metadata_s *meta, rt_uint8_t instance, char *out, rt_size_t outsz);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif /* __UORB_DEVICE_H__ */
